//
//  TopHud.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/8/29.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class TopHud: UIView {
    var text:String!
    var textLabel:UILabel!
    init(frame: CGRect,text:String) {
        textLabel = UILabel()
        super.init(frame: frame)
        self.backgroundColor = Theme.BlueHUD
        self.text = text
        print(self.text)
        self.createLabel()
        self.animateForHUD()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //创建一个显示提示信息的label
    func createLabel(){
        textLabel.frame = CGRect(x: 40, y: 20, width: WidthAPP-80, height: 44)
        textLabel.numberOfLines = 0
        textLabel.textAlignment = .Center
        textLabel.font = BaseFunc.getCustomFont(13)
        textLabel.textColor = UIColor.whiteColor()
        textLabel.text = self.text
        self.addSubview(textLabel)
    }
    
    
    //animate动画
    func animateForHUD(){
        self.center.y -= 64
        UIView.animateWithDuration(0.25, delay: 0, options: .CurveEaseOut, animations: {
            self.center.y += 64
            }) { (end) in
                UIView.animateWithDuration(0.25, delay: 2, options: .CurveEaseOut, animations: {
                    self.center.y -= 64
                }) { (end) in
                    self.removeFromSuperview()
                }
        }
    }
    
    
}













